'use strict';

var mongoose = require('mongoose');
var modelPlugin = require("../model.plugin");
var Schema = mongoose.Schema;
var ObjectId  = Schema.ObjectId;

var contentsSchema = new Schema({
  contentType: {type: Number},
  content: {type: String},
  style: {type: String}
});

var commentsSchema = new Schema({
  userId: {type: ObjectId, ref: 'User'},
  content: {type: String},
  commentTime: {type: Date},
  mood: {type: String},
  reComment: {type: ObjectId}
});

var pathSchema = new Schema({
  name: {type: String},
  timeStr: {type: String},
  description: {type: String},
  userId: {type: ObjectId, ref: 'User'},
  articleId: {type: ObjectId, ref: 'Article'},

  createdAt: {type: Date, default: Date.now},
  createdBy: {type: ObjectId, ref: 'User'},
  updatedAt: {type: Date, default: Date.now},
  updatedBy: {type: ObjectId, ref: 'User'},

  location: {
    description: {type: String},
    longitude: {type: String},
    latitude: {type: String},
    altitude: {type: Number}
  },
  weather: {
    description: {type: String},
    temperature: {type: String},
    WindVelocity: {type: String},
    windDirection: {type: String},
    humidity: {type: String},
    situation: {type: String}
  },
  mood: {
    description: {type: String},
    moodType: {type: Number},
    moodState: {type: Number}
  },
  contents: [contentsSchema],
  comments: [commentsSchema],
  checkeds: [{
    userId: {type: ObjectId, ref: 'User'},
    content: {type: String},
    state: {type: Boolean},
    checkTime: {type: Date}
  }],
  collects: [{
    userId: {type: ObjectId, ref: 'User'},
  }],
  thumbsUp: [{
    userId: {type: ObjectId, ref: 'User'},
  }],
  thumbsDown: [{
    userId: {type: ObjectId, ref: 'User'},
  }]
});

pathSchema.plugin(modelPlugin);
// pathSchema.index({name: 1});

mongoose.model('Part', pathSchema);
